extends Node2D

@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var ray: RayCast2D = $AnimatedSprite2D/RayCast2D

const SPEED = 60

var direction = 1:
	set(v):
		direction = v
		if not is_node_ready():
			await ready
		sprite.scale.x = direction
 
func _physics_process(delta):
	position.x += direction * SPEED * delta

	if ray.is_colliding(): direction = -direction
